//
//  UFUserDefault.m
//  universityFace
//
//  Created by 阮 沧晖 on 14-9-25.
//  Copyright (c) 2014年 阮 沧晖. All rights reserved.
//

#import "UFUserDefault.h"



static UFUserDefault *ufUserDefault;
@implementation UFUserDefault

+ (UFUserDefault *)shared
{
    if (ufUserDefault == nil){
        @synchronized(self){
            ufUserDefault = [[UFUserDefault alloc]init];
            
        }
    }
    return ufUserDefault;
}

- (id)init
{
    self = [super init];
    if (self) {
        userDefaults = [NSUserDefaults standardUserDefaults];
    }
    return self;
}
- (void)setDict:(NSDictionary *)dict{
    
    _dict = dict;
   
//    self.password = dict[kPassword];
    
}


- (void)updateUserDefaults:(id)value forKey:(NSString *)key
{
    [userDefaults setObject:value forKey:key];
}

- (void)updateUserDefaultsBoolValue:(BOOL)value forKey:(NSString *)key
{
    [userDefaults setBool:value forKey:key];
}


- (id)userDefaultValueForKey:(NSString *)key
{
    return [userDefaults objectForKey:key];
}


#pragma mark 保存信息
- (void)saveUser{
    
    [ufUserDefault updateUserDefaults:  self.channel_id  forKey:KUChannel_id];
    [ufUserDefault updateUserDefaults:  self.channel_token  forKey:KUChannel_token];
    [ufUserDefault updateUserDefaults:  self.redis_token  forKey:KURedis_token];
    [ufUserDefault updateUserDefaults:  self.account  forKey:KUAccount];
    [ufUserDefault updateUserDefaults:  self.password  forKey:KUPassword];
    [ufUserDefault updateUserDefaults:  self.exit  forKey:KUFExit];
    
}

- (void)autoLoginUser{
    self.channel_id  = [ufUserDefault userDefaultValueForKey:KUChannel_id];
    self.channel_token  = [ufUserDefault userDefaultValueForKey:KUChannel_token];
    self.redis_token  = [ufUserDefault userDefaultValueForKey:KURedis_token];
    self.account  = [ufUserDefault userDefaultValueForKey:KUAccount];
    self.password  = [ufUserDefault userDefaultValueForKey:KUPassword];
}

- (void)resetLoginInfos{
    [ufUserDefault updateUserDefaults: @"" forKey:KUChannel_id];
     [ufUserDefault updateUserDefaults: @"" forKey:KUChannel_token];
     [ufUserDefault updateUserDefaults: @"" forKey:KURedis_token];
    [ufUserDefault updateUserDefaults: @"" forKey:KUAccount];
    [ufUserDefault updateUserDefaults: @"" forKey:KUPassword];
}




@end
